package com.finalcial.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.finalcial.po.LoginMsg;
import com.finalcial.service.EchatsService;

@Controller
@RequestMapping("echats")
public class EchatsController {
	
	@Resource
	private EchatsService echatsService;
	
	@RequestMapping("/choose")
	public String choose(){
		return "/datamanager/persondata/personalSpecial";
	}
	
	@RequestMapping("/chooseAccount")
	public String chooseAccount(){
		return "/datamanager/persondata/personalAccount";
	}
	@RequestMapping("/chooseMap")
	public String chooseMap(){
		return "/datamanager/persondata/personalMap";
	}
	
	@RequestMapping("listSalary")
	@ResponseBody
	public List<Map<String, Object>> listSalary(HttpServletRequest request,HttpServletResponse response,HttpSession httpSession ){
		LoginMsg loginMsg = (LoginMsg) httpSession.getAttribute("LoginMsg");
		Integer userId = loginMsg.getUserId();	
		String costTypeName = "国内差旅";
		String reimbursementTypeName = costTypeName;
		List<Map<String, Object>> listSalary = echatsService.pandectSalary(userId, costTypeName, reimbursementTypeName);
		return listSalary;		
	}
	
	@RequestMapping("listSalaryProperty")
	@ResponseBody
	public List<Map<String, Object>> listSalaryProperty(HttpServletRequest request,HttpServletResponse response,HttpSession httpSession ){
		LoginMsg loginMsg = (LoginMsg) httpSession.getAttribute("LoginMsg");
		Integer userId = loginMsg.getUserId();	
		String costTypeName = "物业管理";
		String reimbursementTypeName = costTypeName;
		List<Map<String, Object>> listSalary = echatsService.pandectSalary(userId, costTypeName, reimbursementTypeName);
		return listSalary;		
	}
	
	@RequestMapping("listSalaryStaff")
	@ResponseBody
	public List<Map<String, Object>> listSalaryStaff(HttpServletRequest request,HttpServletResponse response ,HttpSession httpSession){
		LoginMsg loginMsg = (LoginMsg) httpSession.getAttribute("LoginMsg");
		Integer userId = loginMsg.getUserId();	
		String costTypeName = "员工福利";
		String reimbursementTypeName = costTypeName;
		List<Map<String, Object>> listSalary = echatsService.pandectSalary(userId, costTypeName, reimbursementTypeName);
		return listSalary;		
	}
	
	@RequestMapping("listSalaryOfficial")
	@ResponseBody
	public List<Map<String, Object>> listSalaryOfficial(HttpServletRequest request,HttpServletResponse response,HttpSession httpSession ){
		LoginMsg loginMsg = (LoginMsg) httpSession.getAttribute("LoginMsg");
		Integer userId = loginMsg.getUserId();	
		String costTypeName = "公务交通";
		String reimbursementTypeName = costTypeName;
		List<Map<String, Object>> listSalary = echatsService.pandectSalary(userId, costTypeName, reimbursementTypeName);
		return listSalary;		
	}
	
	@RequestMapping("listPropertyManager")
	@ResponseBody
	public List<Map<String, Object>> listPropertyManager(HttpSession httpSession){
		LoginMsg loginMsg = (LoginMsg) httpSession.getAttribute("LoginMsg");
		Integer userId =  loginMsg.getUserId();
		List<Map<String, Object>> listPropertyManager = echatsService.listPersonalAccount(userId);	
		for(Map<String, Object> map:listPropertyManager) {//遍历list报销类型
			for(String llist :map.keySet()) {
				System.out.println(llist+"::::"+map.get(llist));
			}
		}
		return listPropertyManager;
	}
	
	
	@RequestMapping("getStartSection")
	@ResponseBody
	public List<String> getStartSection(HttpSession httpSession){
		LoginMsg loginMsg = (LoginMsg) httpSession.getAttribute("LoginMsg");
		Integer userId =  loginMsg.getUserId();
		List<String> listStartSection = echatsService.getStartSection(userId);
		return listStartSection;
	}
	@RequestMapping("getEndSection")
	@ResponseBody
	public Map<String, Object>  getEndSection(HttpServletRequest request,HttpServletResponse response ,HttpSession httpSession){
		LoginMsg loginMsg = (LoginMsg) httpSession.getAttribute("LoginMsg");
		Integer userId =  loginMsg.getUserId();
		Map<String, Object> map = new HashMap<String, Object>();
		String businessTravelStartSection = request.getParameter("businessTravelStartSection");
		String dataIndex = request.getParameter("dataIndex");
		List<String> listEndSection = echatsService.getEndSection(userId, businessTravelStartSection);
		System.out.println(businessTravelStartSection);
		System.out.println(listEndSection);
		map.put("businessTravelStartSection", businessTravelStartSection);
		map.put("listEndSection", listEndSection);
		map.put("dataIndex", dataIndex);
		return map;
	} 
}
